package com.wemedia.controller;

import com.apis.wmUser.AdwemediaApi;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.common.enums.AppHttpCodeEnum;

import com.usian.model.media.pojos.WmUser;
import com.wemedia.service.Wemediaservice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("/wemedia/api/v1")
public class WemediaController  implements AdwemediaApi {
    @Autowired
    private Wemediaservice wemediaservice;

//自媒体名称查询
    @PostMapping("/findByName/{name}")
    @Override
    public WmUser findbyname(@PathVariable("name") String name) {
        if (name!=null && StringUtils.isEmpty(name)){
        WmUser wmUser  =wemediaservice.getOne(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName,name));
             return wmUser;
        }

        return null;
    }
    //自媒体保存
    @PostMapping("/save")
    @Override
    public ResponseResult save(@RequestBody WmUser user) {
       wemediaservice.save(user);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
